﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CIT.WMS.output
{
    public partial class FrmMateBack : Form
    {
        public FrmMateBack()
        {
            InitializeComponent();
        }

        private void txt_reelid_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                //判断料卷是否在线边仓
                StringBuilder str = new StringBuilder();
                str.Append(string.Format(@"select housecode,wocode,reelid,pocode,partnumber,qty,batch1,isnull(shelfid,'') as shelfid from MdcDatVStorage where ReelID='{0}' and housecode='003' union select housecode,wocode,reelid,pocode,partnumber,qty,batch1,isnull(shelfid,'') as shelfid from MdcDatVStorage where ReelID='{0}' and housecode='006'", txt_reelid.Text));
                DataTable dt = Utils.NMS.QueryDataTable(Utils.uContext, str.ToString(), new CIT.WMS.MESWcf.CmdParameter[0]);
                if (dt.Rows.Count == 0)
                {
                    lab_msg.Text = "料卷不在线边仓";
                    lab_msg.ForeColor = Color.Red;
                    txt_reelid.SelectAll();
                    txt_reelid.Focus();
                    return;
                }
                //执行下架动作
                string housecode = dt.Rows[0]["housecode"].ToString();
                str = new StringBuilder();
                str.Append(" update mdcdatvstorage set housecode='001' where reelid='" + txt_reelid.Text + "'");
                ////增加SyssystemLog日志 nancy 2017.07.26
                str.Append(" insert SyssystemLog(Fguid,line,WoCode,SfcNo,ProuctCode,PartNumber,ReelID,pocode,SupplierID,HouseCode,Qty,Remarks,Creator) ");
                str.Append(" select newid(),line,wocode,sfcno,'',PartNumber,ReelID,pocode,SupplierID,'001',Qty,'PDA生产退料', '" + Utils.uContext.UserNamek__BackingField + "' from mdcdatvstorage where reelid='" + txt_reelid.Text + "'");  
                bool flag = false;
                bool result = false;
                Utils.NMS.Exectransql(Utils.uContext, str.ToString(), new CIT.WMS.MESWcf.CmdParameter[0], out flag, out result);
                if (flag)
                {
                    Utils.SaveAppropriationSheet(new AppropriationSheet() { PartNumber = dt.Rows[0]["partnumber"].ToString(), WOCode = dt.Rows[0]["wocode"].ToString(), POCode = dt.Rows[0]["wocode"].ToString(), ReelID = txt_reelid.Text, Qty = dt.Rows[0]["qty"].ToString(), HouseCode = "001", FromHouse = housecode, Description = "生产退料", User = Utils.uContext.UserNamek__BackingField });
                    lab_msg.Text = "退料成功.";
                    lab_msg.ForeColor = Color.Lime;
                    txt_reelid.Text = "";
                    txt_reelid.SelectAll();
                    txt_reelid.Focus();
                    return;
                }
            }
        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}